//保存对应图片----------------
var map2={
    "[呵呵]":"d_hehe",
    "[嘻嘻]":"d_xixi",
    "[哈哈]":"d_haha",
    "[爱你]":"d_aini",
    "[挖鼻屎]":"d_wabishi",
    "[吃惊]":"d_chijing",
    "[晕]":"d_yun",
    "[泪]":"d_lei",
    "[馋嘴]":"d_chanzui",
    "[抓狂]":"d_zhuakuang",
    "[哼]":"d_heng",
    "[可爱]":"d_keai",
    "[怒]":"d_nu",
    "[汗]":"d_han",
    "[害羞]":"d_haixiu",
    "[睡觉]":"d_shuijiao",
    "[钱]":"d_qian",
    "[偷笑]":"d_touxiao",
    "[笑cry]":"d_xiaoku",
    "[doge]":"d_doge",
    "[喵喵]":"d_miao",
    "[酷]":"d_ku",
    "[衰]":"d_shuai",
    "[闭嘴]":"d_bizui",
    "[鄙视]":"d_bishi",
    "[花心]":"d_huaxin",
    "[鼓掌]":"d_guzhang",
    "[悲伤]":"d_beishang",
    "[思考]":"d_sikao",
    "[生病]":"d_shengbing",
    "[亲亲]":"d_qinqin",
    "[怒骂]":"d_numa",
    "[太开心]":"d_taikaixin",
    "[懒得理你]":"d_landelini",
    "[右哼哼]":"d_youhengheng",
    "[左哼哼]":"d_zuohengheng",
    "[嘘]":"d_xu",
    "[委屈]":"d_weiqu",
    "[吐]":"d_tu",
    "[可怜]":"d_kelian",
    "[打哈气]":"d_dahaqi",
    "[挤眼]":"d_jiyan",
    "[失望]":"d_shiwang",
    "[顶]":"d_ding",
    "[疑问]":"d_yiwen",
    "[困]":"d_kun",
    "[感冒]":"d_ganmao",
    "[拜拜]":"d_baibai",
    "[黑线]":"d_heixian",
    "[阴险]":"d_yinxian",
    "[打脸]":"d_dalian",
    "[傻眼]":"d_shayan",
    "[猪头]":"d_zhutou",
    "[熊猫]":"d_xiongmao",
    "[兔子]":"d_tuzi"
};
(function ($) {
    $.fn.extend({
        insertAtCaret: function (myValue) {
            var $t = $(this)[0];
            if (document.selection) {
                this.focus();
                sel = document.selection.createRange();
                sel.text = myValue;
                //this.focus();
            }
            else if ($t.selectionStart || $t.selectionStart == '0') {
                var startPos = $t.selectionStart;
                var endPos = $t.selectionEnd;
                var scrollTop = $t.scrollTop;
                $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
                //this.focus();
                $t.selectionStart = startPos + myValue.length;
                $t.selectionEnd = startPos + myValue.length;
                $t.scrollTop = scrollTop;
            } else {
                this.value += myValue;
                //this.focus();
            }
        }
    })
})(jQuery);

//接受信息转表情--------------
function codetoface(str){
    var reg=/\[([\u4e00-\u9fa5\w])+\]/g;
    if(str.match(reg)){
        var arr3=str.match(reg);
        for(var rr= 0;rr<arr3.length;rr++){
            arr3[rr].index=rr;
            if(arr3[rr].match(reg)){
                str=str.replace(arr3[rr],"<img src='faces2/"+map2[arr3[rr]]+".png'>");
            };
        }
    }
    return str;
}
//页面插入表情区域------------
//$('#faceulplace').load('faceul2.html');
$("#zerofacepage").load("faceul.html #face1list");
$("#onefacepage").load("faceul.html #face2list");
$("#twofacepage").load("faceul.html #face3list");


var mySwiper=null;
$("#facebtn").click(function(){
    //$("#facelist").toggle(200);
    if($("#facelist").css("display")==="block"){
        $("#facelist").css("display","none");
    }
    else if($("#facelist").css("display")=="none"){
        $("#facelist").css("display","block");
        //swiper
        if(!mySwiper){
            mySwiper = new Swiper ('#facelist .swiper-container', {
                paginationClickable: true,
                touchRatio : 1,
                initialSlide :0,
                pagination: '#facelist .swiper-pagination'
            })
        }

    }
});
//插入表情字符
function sendface(e){
    var face=e.dataset.key;
    $("#contentword").insertAtCaret(face);
    $("#contentword").blur();
}
$("#contentword").focus(function(){
    $("#facelist").css("display","none");
});